home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 June: Reference Library / Dev.CD Jun 94.toast / Periodicals / develop / develop Issue 11 / develop 11 code / The NetWork Project / Examples (Sources) / TrivialLookUp.p < prev    next >
Encoding:
Text File  |  1992-07-15  |  4.3 KB  |  194 lines  |  [TEXT/MPS ]

  1. {file TrivialLookUp. This is a sample implementation for a trivial look-up system. 
  2. Include a reference to this file and unit in your "uses" clause, compile and link 
  3. to TrivialLookUp.p.o before linking to NetWorkLib.o.
  4.  
  5. Trivial solutions: 
  6.     Register:     we do not register at all. Hence we can only be addressed, if a local NetWork
  7.                 processor knows us.
  8.     SetSearch:     we only default search allowed.
  9.     Active:        always claim true.
  10.     Random:        return broadcast address
  11.     Next:        return local address
  12.     }
  13.  
  14. {     © Copyright 1991 The NetWork Project, StatLab Heidelberg.   }
  15. {     © Copyright 1991 G. Sawitzki, Heidelberg.   }
  16.  
  17. unit NetWorkLookup;
  18.  
  19. interface
  20.  
  21. { The compile time variables NlServer and NlClient are only included to make
  22. comparisons with full implementations easier}
  23. { use "pascal -d NlServer=false" if you don´t want to register your own names }
  24.  
  25. {$IFC Undefined NlServer}
  26. {$SETC NlServer:=true}
  27. {$ENDC}
  28.  
  29. { use "pascal -d NlClient=false" if you don´t want to look for other programs }
  30.  
  31. {$IFC Undefined NlClient}
  32. {$SETC NlClient:=true}
  33. {$ENDC}
  34.  
  35. uses    Types,
  36.         Errors,
  37.         NetWork;
  38.  
  39.  
  40. {$IFC UNDEFINED UsingAppletalk}
  41. type Str32 = String [32];
  42. {$ENDC}
  43.  
  44. {    =============================================================    }
  45.  
  46. {    name lookup - identication of possible partners }
  47.  
  48. const
  49.     nlVersion    = -31100;    { -- no appletalk version 48 or higher, could be removed }
  50.     nlTaskErr    = -31103;     { -- routines called in wrong order }
  51.     nlNotFound    = -31104;     { -- used internally }
  52.     nlDupReg    = -31105;     { -- called NlRegister twice }
  53.     nlNoReg        = -31106;     { -- called NlDeregister without NlRegister }
  54.     nlAtkOffErr = -31108;    { -- appletalk off, cannot use function }
  55.  
  56.  
  57.     nlLocal        = 0;    { can be used instead of local to denote this machine }
  58.     nlBroadcast    = -1;    { bradcast address, all of this cable }
  59.     
  60. function NlNode : longint;
  61.  
  62. {$IFC NlClient}
  63.  
  64.  
  65. function NlSetSearch (NlName, NlType, NlZone : Str32) : OSErr;
  66.  
  67. {    start/stop of NL task }
  68.  
  69. function NlStart : OSErr;
  70. function NlStop : OSErr;
  71.  
  72. function NlCount : integer;    { or OSErr, if error, NlCount returns the number of partners found. }
  73. function NLActive (who:longint) : boolean;    { is who still on the list ? }
  74. function NLRandom : longint; { any partner. returns 0 on error.}
  75. function NLNext(after:longint) : longint;    { next partner. NLNext(0) retrurns first. returns 0 on error. }
  76. function NlTask : OSErr;        { call this function periodically }
  77. function NlGetSleep : longint;        { time that may elapse until next call to NlTask  }
  78.  
  79. {$ENDC}
  80.  
  81. {$IFC NlServer}
  82.  
  83. {    register a server, pass '' to use choosername, only one entity can be registered }
  84.  
  85. function NlRegister (NlName, NlType : Str32) : OSErr;
  86. function NlDeregister : OSErr;
  87.  
  88. {$ENDC}
  89.  
  90. function NlInit : OSErr;
  91.  
  92. { this function is obsolete and should no longer be used.
  93. function NlExit : OSErr;
  94. }
  95.  
  96. implementation
  97.  
  98.  
  99. {    =============================================================    }
  100.  
  101. {    name lookup - identication of possible partners }
  102.  
  103. { this function returns 0 if appletalk is down or driver/appletalk transport not installed }
  104.  
  105. function NlNode : longint;
  106. begin
  107.     NlNode := 0;
  108. end;
  109.  
  110. {$IFC NlServer}
  111.  
  112. function NlRegister : OSErr;
  113. begin
  114.     NlRegister:=noErr;
  115. end;
  116.  
  117. function NlDeregister : OSErr;
  118. begin
  119.     NlDeregister:=noErr;
  120. end;
  121. {$ENDC}
  122.  
  123. {$IFC NlClient}
  124. function NlSetSearch (NlName, NlType, NlZone : Str32) : OSErr;
  125. {trivial implementation checks whether parameters correspond to defaults =
  126. '=:Network Processor@*' }
  127. begin
  128.     if (NlName<>'=') | (NlType<> 'Network Processor') | (NlZone <>'*')
  129.     then {not default search target}
  130.         NlSetSearch := nlNotFound {error code recycled}
  131.     else
  132.         NlSetSearch := noErr;
  133. end;
  134.         
  135.  
  136. function NlStart : OSErr;
  137. begin
  138.      NlStart := noErr; 
  139. end;
  140.  
  141. function NlStop : OSErr;
  142. begin
  143.     NlStop := noErr;
  144. end;
  145.  
  146. function NlCount : integer;
  147. begin
  148.     NlCount := 0;
  149. end;
  150.     
  151. function NLActive(who:longint):boolean;
  152. begin
  153.     NlActive:=true
  154. end;
  155.  
  156. function NLRandom:longint;
  157. begin
  158.         NLRandom:=nlBroadcast;
  159. end;
  160.  
  161. function NLNext(after:longint):longint;
  162. var scr,NrOthers:integer;
  163. begin
  164.         NLNext:= 0;
  165. end;
  166.  
  167. function NlTask : OSErr;        { call this function periodically }
  168. begin
  169.     NlTask:=NoErr;
  170. end;
  171.  
  172. function NlGetSleep : longint;        { time that may elapse until next call to NlTask  }
  173. begin
  174.     NlGetSleep:=maxlongint;
  175. end;
  176.  
  177. {$ENDC}
  178.  
  179. {    =============================================================    }
  180.  
  181.  
  182. function NlInit : OSErr;
  183. begin
  184.     NlInit:=NoErr;
  185. end;
  186.  
  187. function NlExit : OSErr;
  188. begin
  189.     NlExit:=NoErr;
  190. end;
  191.  
  192.  
  193. end.
  194.